import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    idx: '1', // 歌单页面根据你idx获取对应的排行榜的歌单数据
    player: {
      index: null,
      list: []
    }, // 存储点击歌曲索引和全部歌曲
    isShowfullplayer: false,
    isShowminplayer: false,
    audioinit: {
      isplay: true,
      currenttime: 0, // 播放时长
      url: '',
      ended: null,
      duration: 0,
      progress: '0%'
    },
    playingLyric: null
  },
  mutations: {
    palyLrc (state, t) {
      state.playingLyric = t
    },
    sendCurT (state, c) {
      state.audioinit.currenttime = c
      state.audioinit.progress = (c / state.audioinit.duration * 100).toFixed(2) + '%'
    },
    sendDt (state, d) { // 设置总时间
      state.audioinit.duration = d
    },
    idx (state, index) {
      state.idx = index
    },
    fullplay (state, obj) {
      state.player.index = obj.index
      if (obj.alllist) {
        state.player.list = obj.alllist
      }
      state.isShowfullplayer = true
    },
    showFull (state) {
      state.isShowfullplayer = true
      state.isShowminplayer = false
    },
    changeisShow (state) {
      // state.isShowfullplayer = false
      state.isShowminplayer = true
    },
    sendUrl (state, url) {
      state.audioinit.url = url
    }
  },
  actions: {
    getUrl (ctx, obj) {
      obj.that.axios.get('/api/song/url?id=' + obj.id).then((res) => {
        console.log(res.data)
        if (res.data.code === 200) {
          ctx.commit('sendUrl', res.data.data[0].url)
        }
      })
    }
  },
  modules: {
  }
})
